# frozen_string_literal: true

class OrderBroadcastJob < ApplicationJob
  queue_as :default

  def perform(hotel_id)
    # ActionCable.server.broadcast 'order_channel',
    #                              order: render_message(order),
    #                              current: order.hotel_id
    hotel = Hotel.find_by_id(hotel_id)
    OrderChannel.broadcast_to(hotel,
                              'order': render_message, 'current': 1)
  end

  private

  # rubocop:disable Metrics/AbcSize
  def render_message
    source = %w[微信小程序 ios客户端 Android客户端 直连OTA OMS代下单].sample
    {
      title: '新订单',
      source: source,
      order_no: "#{SecureRandom.uuid}#{rand(999).to_s.rjust(3, '0')}"
        .split('-').join,
      room_no: ('A'..'D').to_a.sample + Random.rand(1299).to_s,
      phone: %w[130 131 132 180 181 188].sample + Random.rand(99_999_999).to_s,
      checkinId: (14_000..16_000).to_a.sample
    }
  end
  # rubocop:enable Metrics/AbcSize
end
